#!/usr/bin/perl
#$Id$
# use tracks api to find and print active projects

use XML::Simple;
use Data::Dumper;

#
# generate hash from stdin
my $tophash = XMLin('-');
#print Dumper($tophash);

if ($tophash =~ /hash/i) {
    &xmlwalk(\%$tophash); 
}

sub xmlwalk {
    my $tophash = $_[0];
    #
    # if the element is "todo", we've found the todo array
    while (my ($element, $value) = each %$tophash ) {
        if ( $element =~ /project/i ) {
            #print ("$element, $value\n");
            while (my ($arrelement,$arrvalue) = each %$value ) {
                #print Dumper($arrelement, $arrvalue);
                if ( $arrvalue->{state} =~ /active/i ) {
                    print ("$arrvalue->{id}->{content}|");
                    print ("$arrelement\n");
                } 
            }
        }
    }
}
